package com.springboot.cloud.sysadmin.organization.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.cloud.sysadmin.organization.entity.param.RoleQueryParam;
import com.springboot.cloud.sysadmin.organization.entity.param.UserQueryParam;
import com.springboot.cloud.sysadmin.organization.entity.po.Role;
import com.springboot.cloud.sysadmin.organization.entity.po.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Set;

/**
 * Created by ZengJian on 2021/2/3 0003 上午 9:22
 */
@Repository
@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    @Select("select r.id from role r,user_role_relation ur where  r.id=ur.role_id and ur.user_id=#{user_id}")
      String getRoles(@Param("user_id") String user_id);

    @Select("select r.id from resource r left join role_resource_relation rm on r.id = rm.resource_id where rm.role_id = #{role_id} and r.id not in (select r.parent_id from resource r inner join role_resource_relation rm on r.id = rm.resource_id and rm.role_id = #{role_id}) ")
      Set<String> getResources(@Param("role_id") String id);


      IPage<Role> selectPageListRole(Page<Role> page, @Param("roleQueryParam") RoleQueryParam roleQueryParam);
}
